﻿Public Class frmInsertarSatelite

    Private Sub frmInsertarSatelite_Activated(sender As Object, e As EventArgs) Handles Me.Activated
        ModuloGeneral.Centrar(Me.Panel1)
    End Sub


    Private Sub frmInsertarSatelite_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.cmbPlaneta.DataSource = New BindingSource(objGestor.listarPlanetaInfo(), Nothing)
        Me.cmbPlaneta.DisplayMember = "Value"
        Me.cmbPlaneta.ValueMember = "Key"
    End Sub

    Private Sub btnSalir_Click(sender As Object, e As EventArgs) Handles btnSalir.Click
        Me.Close()
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs)
        Dim value As Integer = DirectCast(Me.cmbPlaneta.SelectedItem, KeyValuePair(Of Integer, String)).Key
        Me.txtDecimal3.Text = value.ToString
    End Sub

    Private Sub btnOk_Click(sender As Object, e As EventArgs) Handles btnOk.Click

        Dim Validor As New ValidadorDeFormularios(Me, ErrorProvider1)
        Dim FormularioValido As Boolean = Validor.ValidarFormulario()

        If FormularioValido = False Then
            Return
        End If

        Dim strNombre As String = Me.txtString.Text
        Dim numMasa As Decimal = Convert.ToDecimal(Me.txtDecimal1.Text)
        Dim numTemp As Decimal = Convert.ToDecimal(Me.txtDecimal2.Text)
        Dim numDDia As TimeSpan = New TimeSpan(Convert.ToDecimal(Me.txtDate.Text) * 24, 0, 0)
        Dim numDistancia As Decimal = Convert.ToDecimal(Me.txtDecimal3.Text)
        Dim strCaract As String = Me.txtString2.Text
        Dim IdPlaneta As Integer = DirectCast(Me.cmbPlaneta.SelectedItem, KeyValuePair(Of Integer, String)).Key

        Dim lExito As Boolean

        lExito = objGestor.insertarSatelite(strNombre, numMasa, numTemp, numDDia, strCaract, numDistancia, IdPlaneta)
        If lExito Then
            MsgBox("El Satelite se ingreso correctamente.")

            Me.txtString.Text = ""
            Me.txtDecimal1.Text = ""
            Me.txtDecimal2.Text = ""
            Me.txtDate.Text = ""
            Me.txtString2.Text = ""
            Me.txtString.Focus()
        Else
            MsgBox("El Satelite No fue Registrado, por favor verifique...")
        End If
    End Sub

    Private Sub Panel1_Paint(sender As Object, e As PaintEventArgs) Handles Panel1.Paint

    End Sub
End Class